﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using S4Store.Domain.CarSales;
using S4Store.Domain;

namespace S4Store.Models.CarSchedule
{
    public class InputDataModel
    {
        public InputDataModel()
        {
            Month = DateTime.Now;
            CarBrands = new List<CarBrand>();
        }
        public DateTime Month { get; set; }

        public MonthCarSale MonthCarSale { get; set; }

        public List<CarBrand> CarBrands { get; set; }

        public List<BrandData> getBrandData()
        {
            List<BrandData> data = new List<BrandData>();
            foreach (var brand in CarBrands)
            {
                List<MonthCarModelSale> mcms=new List<MonthCarModelSale>();
                foreach(var m in brand.EnableCarModels){
                    var b = MonthCarSale.CarModelSales.FirstOrDefault(t => t.CarModelId == m.Id);
                    if (b == null)
                    {
                        mcms.Add(new MonthCarModelSale { CarModelId = m.Id, Month = Month, CarModel=m });
                    }
                    else
                    {
                        mcms.Add(b);
                    }
                }
                data.Add(new BrandData { CarBrand = brand, MonthCarModelSales = mcms });
            }
            return data;
        }
    }

    public class BrandData
    {
        public CarBrand CarBrand { get; set; }
        public List<MonthCarModelSale> MonthCarModelSales { get; set; }  
    }
}